package cfdt.common.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * OpenAPI 接口文档配置
 *
 */
@Configuration
@RequiredArgsConstructor
public class OpenApiConfig {

    @Value("${version}")
    public static String appVersion;

    /**
     * 接口文档信息
     */
    @Bean
    public OpenAPI openApi() {
        return new OpenAPI()
                .info(new Info()
                        .title("API接口文档")
                        .description("本文档涵盖管理系统的所有API接口，提供详细的接口说明和使用指南。")
                        .version(appVersion)
                        .license(new License()
                                .name("Apache License 2.0")
                                .url("http://www.apache.org/licenses/LICENSE-2.0")
                        )
                        .contact(new Contact()
                                .name("cfdt")
                                .email("chenzhibin1@grgbanking.com")
                        )
                );
                // 配置全局鉴权参数-Authorize
//                .components(new Components()
//                        .addSecuritySchemes(HttpHeaders.AUTHORIZATION,
//                                new SecurityScheme()
//                                        .name(HttpHeaders.AUTHORIZATION)
//                                        .type(SecurityScheme.Type.APIKEY)
//                                        .in(SecurityScheme.In.HEADER)
//                                        .scheme("Bearer")
//                                        .bearerFormat("JWT")
//                        )
//                );
    }


    /**
     * 全局自定义扩展
     */
//    @Bean
//    public GlobalOpenApiCustomizer globalOpenApiCustomizer() {
//        return openApi -> {
//            // 全局添加Authorization
//            if (openApi.getPaths() != null) {
//                openApi.getPaths().forEach((path, pathItem) -> {
//                    // 其他接口统一添加Authorization
//                    pathItem.readOperations()
//                            .forEach(operation ->
//                                    operation.addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION))
//                            );
//                });
//            }
//        };
//    }



}
